//
//  OKSickTreatController.m
//  ZLFastDoctor
//
//  Created by answer on 16/5/22.
//  Copyright © 2016年 LS. All rights reserved.
//

#import "OKSickTreatController.h"

static NSString *OKSickTreatControllerIdentifier = @"OKSickTreatControllerIdentifier";

@interface OKSickTreatController () <UITableViewDataSource, UITableViewDelegate>
//@property (strong, nonatomic) NSArray *data;
@property (strong, nonatomic) UITableViewCell *oldcell;
@property (strong, nonatomic) NSMutableArray *cellArray;
@end

@implementation OKSickTreatController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:OKSickTreatControllerIdentifier];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(sureCallBack)];
}

#pragma mark - 确定回调
- (void)sureCallBack {
    
    if (self.oldcell == nil) {
        [self.navigationController popViewControllerAnimated:YES];
        return;
    }
    
    // 确定治疗方式
    if ([self.delegate respondsToSelector:@selector(surebtnClickCallBack:)]) {
        [self.delegate surebtnClickCallBack:self.oldcell.tag];
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.data.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:OKSickTreatControllerIdentifier forIndexPath:indexPath];
    cell.textLabel.text = self.data[indexPath.row];
    [self.cellArray addObject:cell];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    self.oldcell.accessoryType = UITableViewCellAccessoryNone;
    UITableViewCell *cell = self.cellArray[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    cell.tag = indexPath.row + 2;
    self.oldcell = cell;
}

//- (NSArray *)data {
//    if (_data == nil) {
//        _data = @[@"手术治疗", @"保守治疗", @"药物治疗"];
//    }
//    return _data;
//}

- (NSMutableArray *)cellArray {
    if (_cellArray == nil) {
        _cellArray = [NSMutableArray array];
    }
    return _cellArray;
}


@end
